import { Module } from "@nestjs/common";
import { RedisService } from "./redis.service";
import { RedisOptions } from "ioredis";

@Module({})
export class RedisModule {
    /**
     * 注册redismodule
     * @param name 连接名称
     * @param options 连接配置
     * @returns 
     */
    static register(name: string, options: RedisOptions) {
        return {
          global: true,
          module: RedisModule,
          providers: [
            {
                provide: 'CLIEN_NAME',
                useValue: name,
            },
            {
                provide: 'CONFIG_OPTIONS',
                useValue: options,
            },
            RedisService,
          ],
          exports: [RedisService],
        };
    }
}

